package com.atguigu.guli.edu.controller.admin;

import com.atguigu.common_utils.utils.PageUtils;
import com.atguigu.guli.edu.entity.Teacher;
import com.atguigu.guli.edu.entity.query.TeacherQuery;
import com.atguigu.guli.edu.service.EduTeacherService;
import com.atguigu.guli.service.base.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "讲师管理模块")
@RestController
@RequestMapping("/admin/edu/teacher")

public class AdminTeacherController {

    @Autowired
    EduTeacherService teacherService;

    @ApiOperation("讲师列表分页查询")
    @GetMapping("/list/{page}/{limit}")
    public R getTeacherPageList(@PathVariable("page") Integer page, @PathVariable("limit") Integer limit, TeacherQuery teacherQuery){
        PageUtils pageUtils = teacherService.queryPage(page,limit,teacherQuery);
       return R.ok().data("data",pageUtils);
    }


    @ApiOperation("讲师列表查询")
    @GetMapping("/list")
    public R teacherList(){
        List<Teacher> list = teacherService.list(null);
        return R.ok().data("data",list);
    }

    @ApiOperation("讲师id查询")
    @GetMapping("/info/{id}")
    public R getTeacherId(@PathVariable("id") String id){

        Teacher teacher = teacherService.getById(id);
        return R.ok().data("data",teacher);
    }

    @ApiOperation("保存讲师信息")
    @PostMapping("/save")
    public R saveTeacher(@RequestBody Teacher teacher){
        teacherService.save(teacher);
        return R.ok();
    }
    @ApiOperation("修改讲师信息")
    @PutMapping("/update")
    public R updateTeacher(@RequestBody Teacher teacher){
        teacherService.updateById(teacher);
        return R.ok();
    }
    @ApiOperation("删除讲师信息")
    @DeleteMapping("/delete/{id}")
    public R deleteId(@PathVariable("id")String id){
        teacherService.deleteId(id);
        return R.ok();
    }
    @ApiOperation(("批量删除讲师"))
    @DeleteMapping("/delete/batch")
    public R deletebatch(@RequestBody List<String> ids){
        teacherService.removeByIds(ids);
        return R.ok();
    }
}
